create table if not exists account(
id bigint primary key auto_increment,
name varchar(50),
balance bigint
);
insert into accoaunt(name,balance) VALUES('张三',1000),('李四',1000);
SELECT * from account;
commit -- 提交事务

-- 回滚
start transaction;
update account set balance = balance-100 where name = '张三';

update account set balance =balance -100 where name ='李四';
SELECT * from account;
-- 回滚事务
rollback;
SELECT * from account;-- 回滚事务后，发现修改没撤销了

-- 开启一个事务，执行修改后提交
begin;
update account set balance=balance+100 where name='张三';
select * from account;
commit; -- 提交事务 然后落盘持久化保存
select * from account; 

-- 保存点
begin;
update account set balance =balance+100 where name ='张三';
update account set balance=balance+100 where name='李四';
select * from account;
-- 设置保存点
savepoint savepoint1; 


-- 再次修改
update account set balance =balance+100 where name ='张三';
update account set balance=balance+100 where name='李四';
select * from account;
-- 设置保存点
savepoint savepoint2; 

-- 插入一条新记录
insert into account(name,balance) VALUE('王五',900);
SELECT * from account;

rollback to  savepoint2;
SELECT * FROM account;

rollback to  savepoint1;
SELECT * FROM account;
commit;

-- 自动、手动提交
-- 查看自动提交是否开启 on 开启 off关闭
show variables like 'autocommit';
-- 开关闭自动提交
set autocommit=0;
set autocommit=off;

set autocommit=1
set autocommit=on;

-- 查看隔离级别--事务的隔离级别也是系统变量 默认为
select @@global.transaction_isolation; -- 查看全局 repeatable-read;

select @@session.transaction_isolation;-- 查看当前会话


-- 设置隔离级别 注意：隔离级别名当中有空格的要用-代替 如：repeatable read 中的空格要写成- repeatable-read
-- 方式一
set global transaction_isolation ='serializable';
set global transaction_isolation ='repeatble-read';
/*
设置global 当前开启的所有会话不会被修改，新开的会话被修改，可以查询到被修改了



